package com.behome.netty.common;

import com.behome.netty.common.util.CmdKit;
import com.behome.netty.netty_A.bean.ProtocolAPacket;
import com.behome.netty.netty_A.enums.ProtocolA50Annotation;
import com.behome.netty.netty_B.bean.BusinessReBackBase;
import com.behome.netty.netty_B.enums.ReBackAnnotation;
import com.behome.netty.netty_D.bean.BusinessCmdBase;
import com.behome.netty.netty_D.enums.TerminalDAnnotation;

import java.util.Map;

public class CapCmdManager {
    private static Map<Byte, Class<ProtocolAPacket>> protocolATypeClassMap;
    private static Map<Byte, Class<BusinessReBackBase>> protocolBClassMap;

    private static Map<Byte, Class<BusinessCmdBase>> protocolDClassMap;

    public CapCmdManager() {
    }

    public static void initCmdTypeMap() {
        protocolATypeClassMap = CmdKit.mapCmdTypeIntoCmdClass(ProtocolAPacket.class, ProtocolA50Annotation.class, "type", "getValue", "com.behome.netty.netty_A.bean.A50Bean");
        protocolBClassMap = CmdKit.mapCmdTypeIntoCmdClass(BusinessReBackBase.class, ReBackAnnotation.class, "type", "getValue", "com.behome.netty.netty_B.bean");
        protocolDClassMap = CmdKit.mapCmdTypeIntoCmdClass(BusinessCmdBase.class, TerminalDAnnotation.class, "type", "getValue", "com.behome.netty.netty_D.bean");
    }

    public static Class<ProtocolAPacket> getProtocolAClass(Byte type) {
        return protocolATypeClassMap != null && type != null && protocolATypeClassMap.containsKey(type) ? protocolATypeClassMap.get(type) : null;
    }

    public static Class<BusinessReBackBase> getProtocolBClass(Byte type) {
        return protocolBClassMap != null && type != null && protocolBClassMap.containsKey(type) ? protocolBClassMap.get(type) : null;
    }

    public static Class<BusinessCmdBase> getProtocolDClass(Byte type) {
        return protocolDClassMap != null && type != null && protocolDClassMap.containsKey(type) ? protocolDClassMap.get(type) : null;
    }

    static {
        initCmdTypeMap();
    }
}
